Skip to content

overridable: Implement for custom fields #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

palkerecsenyi
Copy link
Member

@palkerecsenyi palkerecsenyi commented Jul 16, 2025

Closes #297


This is a draft proposal of a solution for this issue, please let me know if you have any suggestions on how to better implement it.

Description

  • This commit demonstrates a potential method of implementing Overridable support for custom fields.

  • When creating a custom field UI definition, the user simply has to specify an additional id prop with their desired ID value for the Overridable. Then, they can specify a parametrize in the overridableRegistry/mapping.js as usual.

  • The aim is to have a set of common props that can be applied to all the field widgets, similarly to
    Ensure consistent use of Overridable in deposit form invenio-app-rdm#3103.

  • This commit makes the necessary changes to two of the UI widgets as a demonstration. When parameterizing, the user has to reference e.g. AutocompleteDropdownComponent instead of AutocompleteDropdown. These are both exported.

  • On its own, this feature is not helpful: users could simply change the props they assign in the Python dictionary instead of using an override. Instead, this is intended to be used in conjunction with dynamicParametrize (created in overridable: add dynamicParametrize function #300) to allow users to dynamically change the props of their custom fields based on the form state.

Full example

In the custom fields definitions file:

CERN_CUSTOM_FIELDS_UI = {
    "section": "CERN",
    "ui_widget": "CERNFields",
    "fields": [
        dict(
            field="cern:departments",
            ui_widget="Dropdown",
            display_url="https://scientific-info.cern/archives/history_CERN/internal_organisation/20s",
            props=dict(
                label="Department",
                icon="building",
                description="Please select a recognised department from the list if applicable e.g BE, EN, HR etc.",
                search=False,
                multiple=True,
                sort_by="title_sort",
                clearable=True,
                autocompleteFrom="/api/vocabularies/departments",
                id="CdsRdm.CustomFields.Department", # New added field
            ),
        ),
        # ...

Then, in assets/js/invenio_app_rdm/overridableRegistry/mapping.js:

export const overriddenComponents = {
  "CdsRdm.CustomFields.Department": parametrize(DropdownComponent, {
    helpText: "Choose your favourite department",
    required: true,
  }),
}

* This commit demonstrates a potential method of implementing
`Overridable` support for custom fields.

* When creating a custom field [UI
definition](https://inveniordm.docs.cern.ch/customize/metadata/custom_fields/records/#upload-deposit-form),
the user simply has to specify an additional `id` prop with their
desired ID value for the Overridable. Then, they can specify a
`parametrize` in the `overridableRegistry/mapping.js` as usual.

* The aim is to have a set of common props that can be applied to all
the field widgets, similarly to
inveniosoftware/invenio-app-rdm#3103.

* This commit makes the necessary changes to two of the UI widgets as a
demonstration. When parameterizing, the user has to reference e.g.
`AutocompleteDropdownComponent` instead of `AutocompleteDropdown`. These
are both exported.
* fieldComponents contains some helpers that are used by field
components in other Invenio modules such as `invenio-app-rdm` and
`invenio-vocabularies`. In the future, it may also be used by custom
field implementors.

* This commit exports it at the top level of the package
palkerecsenyi added a commit to palkerecsenyi/docs-invenio-rdm that referenced this pull request Jul 18, 2025
* As part of
inveniosoftware/react-invenio-forms#298, UI
widgets are being given a standardised common set of props (on top of
which each widget can have additional, more specific props)

* This PR changes the reference docs for custom field widgets by
splitting into the two distinct sections of "common props" and
"widget-specific props"
palkerecsenyi added a commit to palkerecsenyi/docs-invenio-rdm that referenced this pull request Jul 18, 2025
* As part of
inveniosoftware/react-invenio-forms#298, UI
widgets are being given a standardised common set of props (on top of
which each widget can have additional, more specific props)

* This PR changes the reference docs for custom field widgets by
splitting into the two distinct sections of "common props" and
"widget-specific props"
* Implemented the standardised props and dynamic-ID overridable wrapper
for all the UI widgets available for use in custom widgets.
@palkerecsenyi palkerecsenyi force-pushed the custom-field-overridable branch from 9baaeb9 to ac1ebf6 Compare July 25, 2025 12:14
palkerecsenyi added a commit to palkerecsenyi/invenio-app-rdm that referenced this pull request Jul 25, 2025
* Added an injection of the field ID (e.g. `cern:department`) to the
React UI widget chosen for the custom field via a new `id` prop.

* This is consumed by the new function in
inveniosoftware/react-invenio-forms#298 and used
to allow developers to dynamically parametrize their own custom fields
based on the form state.

* This is not a breaking change and shouldn't affect any existing custom
fields
palkerecsenyi added a commit to palkerecsenyi/invenio-app-rdm that referenced this pull request Jul 25, 2025
* Added an injection of the field ID (e.g. `cern:department`) to the
React UI widget chosen for the custom field via a new `id` prop.

* This is consumed by the new function in
inveniosoftware/react-invenio-forms#298 and used
to allow developers to dynamically parametrize their own custom fields
based on the form state.

* This is not a breaking change and shouldn't affect any existing custom
fields
palkerecsenyi added a commit to palkerecsenyi/invenio-app-rdm that referenced this pull request Jul 25, 2025
* Added an injection of the field ID (e.g. `cern:department`) to the
React UI widget chosen for the custom field via a new `id` prop.

* This is consumed by the new function in
inveniosoftware/react-invenio-forms#298 and used
to allow developers to dynamically parametrize their own custom fields
based on the form state.

* This is not a breaking change and shouldn't affect any existing custom
fields
* Added helpText support for the generic SelectField
* Ensured Dropdown and AutoComplete handle helpText and disabled props
correctly
@palkerecsenyi palkerecsenyi marked this pull request as ready for review July 28, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

custom fields: Add Overridable support
1 participant